home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
BPAS9.ARJ
/
ELECTRIC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-09-07
|
2KB
|
80 lines
PROGRAM Electricity; { See Tom Swan pp. 69-71 }
CONST
MaxRow = 12; { Number rows in table }
MaxCol = 8; { Number columns in table }
VAR
StartHours,
HourlyIncrement,
StartWatts,
WattsIncrement,
CostPerKwh : Real;
PROCEDURE Initialize;
BEGIN
WriteLn( ' Cost of electricity' );
WriteLn;
Write( ' Starting number of hours .......? ' ); ReadLn( StartHours );
Write( ' Hourly increment ...............? ' ); ReadLn( HourlyIncrement );
Write( ' Starting number of Watts .......? ' ); ReadLn( StartWatts );
Write( ' Watts increment ................? ' ); ReadLn( WattsIncrement );
Write( ' Cost per kilowatt hour (KWH) ...? ' ); ReadLn( CostPerKwh)
END; {Initialize}
FUNCTION Cost( Time, Power, Rate : Real ) : Real;
{ Return cost of running at "Power" watts for "Time" hours }
BEGIN
Cost := Rate * ( Power * 0.001 * Time )
END; {Cost}
PROCEDURE PrintTable;
VAR
Row, Col : Integer;
Hours, Watts : Real;
BEGIN
WriteLn;
Write( 'Hrs/Watts' );
Watts := StartWatts;
For Col := 1 to MaxCol DO
BEGIN
Write( Watts:8:0 );
Watts := Watts + WattsIncrement
END; {for }
WriteLn;
Hours := StartHours;
For row := 1 to MaxRow DO
BEGIN
WriteLn;
Write( Hours:6:1, '-' );
Watts := StartWatts;
FOR Col := 1 to MaxCol DO
BEGIN
Write( Cost( Hours, Watts, CostPerKwh ):8:2 );
Watts := Watts + WattsIncrement
END; {for}
Hours := Hours + HourlyIncrement
END; { for }
WriteLn;
WriteLn;
WriteLn( 'Cost of Electricity @ ', CostPerKwh:0:4, ' per KWH' )
END; {PrintTable}
FUNCTION Finished : Boolean;
VAR
answer : Char;
BEGIN
WriteLn;
Write( 'Another table (y/n) ? ' );
ReadLn( answer );
Finished := Upcase( answer ) <> 'Y'
END; {Finished }
BEGIN
REPEAT
Initialize;
PrintTable
UNTIL Finished
END.